package com.cjx.stars.controller;

import com.cjx.stars.common.MyException;
import com.cjx.stars.common.Response;
import com.cjx.stars.common.ResponseUtils;
import com.cjx.stars.service.FollowService;
import com.cjx.stars.utils.RegexValidationUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import static com.cjx.stars.constant.FailMessage.PARAMETER_ABNORMAL;

/**
 * @author cjx
 * @description 关注相关控制器
 * @createDate 2024/4/12 15:02
 **/
@RestController
@RequestMapping("/follow")
@Slf4j
public class FollowController {

    @Resource
    FollowService followService;

    @PostMapping("{userId}")
    public Response<?> followOrCancelUser(@PathVariable("userId") Long userId){
        if (!RegexValidationUtils.checkId(userId)) {
            throw new MyException(PARAMETER_ABNORMAL);
        }
        return followService.followOrUnfollowUser(userId);
    }

    @GetMapping("/my")
    public Response<?> myFollowList(@RequestParam int currentPage){
        if (currentPage <= 0) {
            throw new MyException(PARAMETER_ABNORMAL);
        }
        return followService.myFollowList(currentPage);
    }

    @GetMapping("/fans")
    public Response<?> myFansList(@RequestParam int currentPage){
        if (currentPage <= 0) {
            throw new MyException(PARAMETER_ABNORMAL);
        }
        return followService.myFansList(currentPage);
    }

}
